#include "include/types.h"
#include "include/mm.h"

/*
 * Page allocation function
 * @return physical page address
 */
unsigned long alloc_page() {
  unsigned long addr = 0;

  for (long i = KERNEL_PAGE_NUM; i < mem_size / PAGE_SIZE; i++) {
    if (pages[i] == 0) {
      pages[i] = 1; // Mark occupancy
      addr = i * PAGE_SIZE;
      break;
    }
  }

  return addr;
}

/*
 * Page free function
 * @param addr physical page address
 */
void free_page(uint64_t addr) {
  uint32_t index = addr / PAGE_SIZE;
  pages[index] = 0; // Mark idle
}